﻿Imports System.Data
Imports VSModel
Imports Cls_Common

Partial Class FrontEnd_Control_Category_CateMenu
    Inherits System.Web.UI.UserControl
    Public strMenu As String = ""
    Public strMenu2 As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            CreateMenu()
            CreateMenu2()
        End If


    End Sub
    Protected Sub CreateMenu2()

        Using data As New VSEntities
            Dim p = (From q In data.Categories Where q.ParentId = 0 Order By q.Sort Select q).Skip(25).ToList
            For Each cate In p
                strMenu2 = strMenu2 & "<li>" & "<a href='" & MainDomain & "ban-oto/" & cate.QueryString & "-" & cate.CatId.ToString & ".html'>" & "<span class='mn-l-icon alias-29'></span>" & cate.Title & CalCulateOtoByCate(cate.CatId) & "</a>"
                strMenu2 = strMenu2 & CreateSubMenu(cate.CatId)
                strMenu2 = strMenu2 & "</li>"
            Next
        End Using

    End Sub
    Protected Sub CreateMenu()

        Using data As New VSEntities
            Dim p = (From q In data.Categories Where q.ParentId = 0 Order By q.Sort Select q).Skip(0).Take(25).ToList
            For Each cate In p
                strMenu = strMenu & "<li>" & "<a href='" & MainDomain & "ban-oto/" & cate.QueryString & "-" & cate.CatId.ToString & ".html'>" & "<span class='mn-l-icon alias-29'></span>" & cate.Title & CalCulateOtoByCate(cate.CatId) & "</a>"
                strMenu = strMenu & CreateSubMenu(cate.CatId)
                strMenu = strMenu & "</li>"
            Next
        End Using

    End Sub

    Protected Function CreateSubMenu(ByVal ParentId As Integer) As String

        Dim strSub = ""
        Using data As New VSEntities
            Dim p = (From q In data.Categories Where q.ParentId = ParentId Order By q.Sort Select q).ToList
            If Not p Is Nothing AndAlso p.Count > 0 Then
                strSub = strSub & "<ul class='Hidden'>"
                Dim i As Integer = 0
                For Each cate In p

                    If i = 0 Or i Mod 2 = 0 Then
                        strSub = strSub & "<li class=""Break"">"
                    End If



                    strSub = strSub & "<a class='SubMenu' href='" & MainDomain & "ban-oto/" & cate.QueryString & "-" & cate.CatId.ToString & ".html'>" & cate.Title & "</a>"

                    'check if subMenu has Child
                    'Dim _ParentId = cate.CatId
                    'Dim k = (From q In data.Categories Where q.ParentId = _ParentId Order By q.Sort Select q).ToList
                    'If Not k Is Nothing AndAlso k.Count > 0 Then
                    '    strSub = strSub & CreateSubMenu(_ParentId)
                    'End If
                    If i = p.Count Or i Mod 2 = 1 Then
                        strSub = strSub & "</li>"
                    End If
                    i = i + 1


                Next
                strSub = strSub & " </ul>"

            End If
        End Using

        Return strSub

    End Function
    Function CalCulateOtoByCate(ByVal _CateId As Integer) As String
        Return ""
        'Dim count As Integer = 0


        'Using data As New VSEntities

        '    Dim a = (From r In data.uspSelectSubCate(_CateId) Select r.CateID).ToArray
        '    count = (From q In data.RaoVats Where (a.Contains(q.CateID) Or q.CateID = _CateId) And q.StatusId = 3 _
        '                                        And q.PublishedDate <= Now() And (q.eEffectiveDate >= Now() _
        '                                        Or q.eEffectiveDate Is Nothing) Select q.RaovatId).Count

        'End Using
        'Return " (" & count.ToString & ")"
    End Function

    
    
End Class
